/**
 * Created by Administrator on 2015/9/6.
 */
var express = require('express');
var router = express.Router();
var adminService = require('../src/service/adminService');
/**跳转到添加用户页面*/
router.get('/peopleManagement/toAddUser', function (req, res, next) {
    res.render('EJS/admin/peopleManagement/addUser', {title: 'Express'});
});
/**添加用户*/
router.post('/peopleManagement/addUser', function (req, res, next) {
    adminService.addUser(req, res, function (result) {
        res.redirect('/admin/peopleManagement/userList');
    });

});
/**用户列表*/
router.get('/peopleManagement/userList', function (req, res, next) {
    adminService.queryAllUser(req, function (result, pageNo) {
        res.render('EJS/admin/peopleManagement/userList', {users: result.content, pageNo: pageNo});
    });
});
/**管理员查看用户详细信息*/
router.get('/peopleManagement/updateUser', function (req, res, next) {
    adminService.updateUser(req, res, function (result) {
        var obj3 = eval(result);
        res.render('EJS/admin/peopleManagement/updateUser', {user: result[0]});
    })
});
router.get('/peopleManagement/toUpdateUser', function (req, res, next) {
    adminService.updateUser(req, res, function (a) {
        var obj3 = eval(a);
        res.render('EJS/admin/peopleManagement/updateUser', {user: obj3[0]});
    })
});
/**检查手机号码是否重复*/
router.post('/peopleManagement/checkTel', function (req, res, next) {
    adminService.queryTel(req, res, function (a) {
        var obj1 = eval(a);
        res.send(obj1);
    })
});

/**检查手机号码是否存在*/
router.post('/peopleManagement/checkTelExist', function (req, res, next) {
    adminService.queryTelExist(req, res, function (a) {
        var obj1 = eval(a);
        res.send(obj1);
    })
});
/**更改用户详细信息*/
router.post('/peopleManagement/updateUser', function (req, res, next) {
    adminService.updatePersonInfo(req, res, function (a) {
        var obj3 = eval(a);
        //res.render('EJS/admin/peopleManagement/updateUser', { user:obj3.code });
        res.redirect('/admin/peopleManagement/userList')
    })
});

/**条件搜索用户*/
router.post('/peopleManagement/userList', function (req, res, next) {
    adminService.queryUser(req, res, function (result) {
        res.render('EJS/admin/peopleManagement/userListByName', {users: result});
    });
});
/**删除用户*/
router.get('/peopleManagement/delUserList', function (req, res, next) {
    adminService.delUser(req, res, function (a) {
        res.redirect('/admin/peopleManagement/userList');
    });
});

module.exports = router;